package com.atguigu.mr.order;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @description: xxx
 * @time: 20191228 21:54
 * @author: baojinlong
 **/
public class OrderMapper extends Mapper<LongWritable, Text, OrderBean, NullWritable> {
    private OrderBean orderBean = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 0000001212 pt_01 2222.8
        // 1.获取一行
        String line = value.toString();
        // 2.切割
        String[] fields = line.split("\t");
        // 封装bean对象
        orderBean.setOrderId(Integer.parseInt(fields[0]));
        orderBean.setPrice(Double.parseDouble(fields[2]));
        // 写出
        context.write(orderBean, NullWritable.get());
    }
}
